/*****************************************************************************************
* Master file matching & recoding BHPS and UKHLS data						             *
*****************************************************************************************/

* merge individual and household level data
do "SET_YOUR_PATH_FOR_INPUT\BHPS\bhps_merge_individual_hh.do"

* combine bhps and ukhls data across waves in long-format
do "SET_YOUR_PATH_FOR_INPUT\BHPS\bhps_combine_bhps_and_ukhls.do"

*merge person-specific and combined data
do "SET_YOUR_PATH_FOR_INPUT\BHPS\bhps_merge_personal_and_combined_data.do"


*** done


******************************
*** Recode variables *********
******************************

cd "SET_YOUR_PATH_FOR_INPUT_and_OUTPUT\BHPS\combined"

use "all_indresp_hh_pers.dta", clear

drop if wave==.
gen year = 1990 + wave


***** Household-level data

*gross hh-income
clonevar hhinc_gross = fihhmngrs_dv

drop if fihhmngrs_dv>700000 & fihhmngrs_dv<800000	// drop really high income (n=1)
drop if fihhmngrs_dv<-40000 	// drop really high negative income (n=6)

mvdecode lfsat2 finnow sclfsat2 hhsize age sex jbstat hiqualb_dv  vote6 fvote6 mvote6 votenorm polcost, mv(-10/-1)
mvdecode voteintent perpolinf, mv(-10/-1 11)
mvdecode fihhmngrs_dv ffihhmngrs_dv mfihhmngrs_dv, mv(-9)
mvdecode yphsw yphap yphfm yphfr yphsc yphlf, mv(-9/-1)

*satisfaction with financial situation
mvdecode finnow mfinnow ffinnow, mv(-10/-1)
rev finnow, gen(satfin)

*satisfaction with life
clonevar satlife = lfsato
replace satlife = sclfsato if satlife==.
mvdecode satlife, mv(-10/-1)

rev yphlf, gen(ysatlife)

*satisfaction with health
clonevar sathealth = lfsat1
replace sathealth = sclfsat1 if sathealth==.
mvdecode sathealth, mv(-10/-1)

*satisfaction with household-income
clonevar sathhinc = lfsat2
replace sathhinc = sclfsat2 if sathhinc==.
mvdecode sathhinc, mv(-10/0)


*material deprivation
mvdecode matdepa matdepi matdepj matdepd matdepe matdepf matdepg matdeph ///
	mmatdepa mmatdepi mmatdepj mmatdepd mmatdepe mmatdepf mmatdepg mmatdeph ///
	fmatdepa fmatdepi fmatdepj fmatdepd fmatdepe fmatdepf fmatdepg fmatdeph, mv(-10/-1)

gen matdep_stuff = .
replace matdep_stuff = 1 if (matdepg==2 | matdeph==2)
replace matdep_stuff = 0 if (matdepg!=2 & matdepg!=. & matdeph!=2 & matdeph!=.)
recode matdepj (2=1)(1 3 4=0)(else=.), gen(matdep_bills) 


*income
gen hhinc = fihhmngrs_dv
gen hhinc_pp = fihhmngrs_dv/hhsize
gen hhinc_pp_sqrt = fihhmngrs_dv/(sqrt(hhsize))

xtile hhinc_dec = hhinc, nq(10) 
xtile hhinc_dec_pp = hhinc_pp, nq(10) 
xtile hhinc_dec_pp_sqrt = hhinc_pp_sqrt, nq(10) 

clonevar hhinc_sat = sathhinc
gen hhinc_dec10 = (hhinc_dec-1)*(10/9)
gen hhinc_dec_pp10 = (hhinc_dec_pp-1)*(10/9)
gen hhinc_dec_pp_sqrt10 = (hhinc_dec_pp_sqrt-1)*(10/9)

gen hhinc_sat10 = (sathhinc-1)*(10/6)

*personal income
clonevar inc_gross = paygu_dv

*sex
recode sex (1=0 "male")(2=1 "female"), gen(sex1)
drop sex
rename sex1 sex
clonevar female = sex

*year of birth
mvdecode birthy, mv(-9/-1 9898)

*age
fre age_dv
recode age_dv (-9=.), gen(age2)
mvdecode birthy, mv(-9/-1 9898)
gen age = year-birthy
recode age (13/25=1)(26/120=0)(else=.), gen(age1825)
recode age (13/35=1)(36/120=0)(else=.), gen(age1835)

center age, gen(age_c)
gen age18 = age-18

*marital status
fre mastat_dv

*employment status
fre jbstat
recode jbstat (3=1 "unemployed")(1 2 4/97=0 "other")(else=.), gen(unemployed)
recode jbstat (4/97=1 "not in labor force")(1/3=0 "other")(else=.), gen(nlf)

*education
mvdecode hiqualb_dv hiqual_dv, mv(-8 -9)
gen edu = hiqual_dv 
replace edu = hiqualb_dv if hiqual_dv==.
recode edu (1=6 "uni degree") (2=5 "other higher degree") (3=4 "A-levels") ///
	(4=3 "GCSE")(5=2 "other qual")(9=1 "no qual")(else=.), gen(edur)
sort pidp year
by pidp: egen edu_max = max(edur)
recode edu_max (4/6=1 "high")(1/3=0 "low")(else=.),gen(edu_max2)

recode edu (5 9=1 "low")(1/4=0 "other")(else=.), gen(edu_low)
recode edu (4=1 "medium")(1 2 3 5 9=0 "other")(else=.), gen(edu_med)
recode edu (1 2 3=1 "high")(4/9=0 "other")(else=.), gen(edu_high)


*migration status
fre migrant


*** political variables 

*vote & participation
fre vote3 	// party vote for at next election
recode vote6 (1=4 "very interested")(2=3 "fairly interested")(3=2 "not very interested") ///
			(4=1 "not at all interested")(else=.), gen(polint)
recode fvote6 (1=4 "very interested")(2=3 "fairly interested")(3=2 "not very interested") ///
			(4=1 "not at all interested")(else=.), gen(f_polint)
recode mvote6 (1=4 "very interested")(2=3 "fairly interested")(3=2 "not very interested") ///
			(4=1 "not at all interested")(else=.), gen(m_polint)

gen polint10 = (polint-1)*(10/3)
			
recode ypvte6 (1=3 "very interested")(2=2 "fairly interested")(3=1 "not interested") (else=.), gen(y_polint)			

clonevar polint_comb = y_polint
replace polint_comb = 3 if polint==4 & polint_comb==.
replace polint_comb = 2 if polint==3 & polint_comb==.
replace polint_comb = 1 if (polint==1 | polint==2) & polint_comb==.

lab var polint_comb "Political Interest (Combined Adult and Youth)"

recode polint_comb (1=0 "none")(2=0.5)(3=1 "very interested")(else=.), gen(polint_comb_lpm)
recode polint_comb (1=0 "none")(2 3=1 "very interested")(else=.), gen(polint_comb01)


recode ypfpolitm (1=6 "most days")(2=5)(3=4)(4=3)(5=2)(6=1 "never")(else=.), gen(polact)
lab var polact "Go to political meeting/march, rally or demonstration"
			
fre vote7 // participation in last election

// 
recode vote3 (95 -2 -1 = 0 "not vote")(1/13 97=1 "vote")(else=.), gen(vote)
recode vote3 (95 -2 = 0 "not vote")(1/13 97=1 "vote")(else=.), gen(vote_1)
recode vote3 (95 -2 = 0 "not vote")(-1 1/13 97=1 "vote")(else=.), gen(vote_2)


// political participation: vote and/or party support
gen polsup = .
replace polsup = 0 if vote3==-2 | vote3==-1 | vote3==95 
replace polsup = 1 if vote1==1 | vote2==1
replace polsup = 1 if (vote3>=1 & vote3<=13) | vote3==97

*no vote variable in 1992:
replace polsup = 0 if (vote1==2 & year==1992) 
replace polsup = 1 if (vote1==2 & vote2==1 & year==1992) 


// pol support
recode demorient (1=4 "very satisfied")(2=3)(3=2)(4=1 "very dissatisfied")(else=.), gen(satdem)	// only UKHLS
recode vote1 (1=1 "yes")(2=0 "no")(else=.), gen(partysup)
clonevar votemdiff = perpolinf
recode civicduty (1=5 "str agree")(2=4)(3=3)(4=2)(5=1 "str disagree")(else=.), gen(voteduty)
recode perbfts (1=5 "str agree")(2=4)(3=3)(4=2)(5=1 "str disagree")(else=.), gen(vote_persben)
recode grpbfts (1=5 "str agree")(2=4)(3=3)(4=2)(5=1 "str disagree")(else=.), gen(vote_grpben)
recode poleff1 (1=5 "high efficacy")(2=4)(3=3)(4=2)(5=1 "low efficacy")(else=.), gen(inteff1)
recode poleff2 (1=5 "high efficacy")(2=4)(3=3)(4=2)(5=1 "low efficacy")(else=.), gen(inteff2)
recode poleff3 (5=5 "high efficacy")(4=4)(3=3)(2=2)(1=1 "low efficacy")(else=.), gen(exeff1)
recode poleff4 (5=5 "high efficacy")(4=4)(3=3)(2=2)(1=1 "low efficacy")(else=.), gen(exeff2)

egen inteff = rowmean(inteff1 inteff2)
egen exeff = rowmean(exeff1 exeff2)

clonevar voteintent10 = voteintent
gen satdem10 = (satdem-1)*(10/3)
clonevar votemdiff10 = votemdiff
gen voteduty10 = (voteduty-1)*(10/4)
gen vote_persben10 = (vote_persben-1)*(10/4)
gen vote_grpben10 = (vote_grpben-1)*(10/4)
gen votenorm10 = ((6-votenorm)-1)*(10/4)
gen polcost10 = ((6-polcost)-1)*(10/4)
gen inteff10 = (inteff-1)*(10/4)
gen exeff10 = (exeff-1)*(10/4)



*** Save final file
save bhps_ukhls_long.dta, replace









